package deepclone;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-03-22
 * Time: 19:28
 */

public class Client {
    public static void main(String[] args) throws CloneNotSupportedException {
        DeepProtoType d = new DeepProtoType();
        d.name = "宋江";
        d.deepCloneableTarget = new DeepCloneableTarget("大牛","大牛对应的类");

        //方式一 深拷贝
        DeepProtoType d2 = (DeepProtoType) d.clone();

        System.out.println("d.name=" + d.name + "d.deepCloneableTarget=" + d.deepCloneableTarget.hashCode());
        System.out.println("d2.name=" + d2.name + "d2.deepCloneableTarget=" + d2.deepCloneableTarget.hashCode());
        //d.name=宋江d.deepCloneableTarget=460141958
        //d2.name=宋江d2.deepCloneableTarget=1163157884
        //哈希Code不一样

        System.out.println("----------------序列化深拷贝---------------");
        //方式二 完成深拷贝
        DeepProtoType p2 = (DeepProtoType) d.deepClone();
        System.out.println("d.name=" + d.name + "d.deepCloneableTarget=" + d.deepCloneableTarget.hashCode());
        System.out.println("p2.name=" + p2.name + "p2.deepCloneableTarget=" + p2.deepCloneableTarget.hashCode());



    }
}
